#ifndef PD_ANDROID_H
#define PD_ANDROID_H

#define _XOPEN_SOURCE
#include <sys/time.h>
#include <sys/select.h> 
#include <dlfcn.h>
#include <unistd.h>

#include <jni.h>
#include <android/log.h>

#define PD_UDK_API 
#define PD_DLLIMPORT
#define PD_RTLIBPREFIX "lib"
#define PD_RTLIBSUFFIX ".so"

#ifndef LOG_TAG
#define LOG_TAG "UDK"
#endif


#ifndef CONDITION
#define CONDITION(cond)     (__builtin_expect((cond)!=0, 0))
#endif

/*
 * Log a fatal error.  If the given condition fails, this stops program
 * execution like a normal assertion, but also generating the given message.
 * It is NOT stripped from release builds.  Note that the condition test
 * is -inverted- from the normal assert() semantics.
 */
#define LOG_ALWAYS_FATAL_IF(cond, ...) \
    ( (CONDITION(cond)) \
    ? ((void)__android_log_assert(#cond, LOG_TAG, __VA_ARGS__)) \
    : (void)0 )

#define LOG_ALWAYS_FATAL(...) \
    ( ((void)__android_log_assert(NULL, LOG_TAG, __VA_ARGS__)) )


#define UDK_PRINT(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__);
#define UDK_LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__);
#define UDK_LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__);
#define UDK_LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__);
#define UDK_LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__);
#define UDK_LOGFATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
#define UDK_LOGIF(cond,...) \
	( (CONDITION(cond)) \
    ? (__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
    : (void)0 )
#define UDK_LOGFATAL_IF(cond,...) LOG_ALWAYS_FATAL_IF(cond, __VA_ARGS__)

#define UDK_DUMP(prefix,d,l) udk_dump(prefix,d,l)


#endif

